package com.syn.synold4s.control.dialog;

import static com.gaoyi.basemodule.baseUtil.OKHttpUtil.BASE_NET_URL;
import static com.gaoyi.basemodule.baseUtil.OKHttpUtil.HELMET_IMG_URL;
import android.content.Context;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.gaoyi.basemodule.baseUtil.ImageUtil;
import com.gaoyi.basemodule.baseUtil.SPUtil;
import com.gaoyi.basemodule.baseconstant.SPName;
import com.gaoyi.basemodule.basedialog.BaseFragmentDialog;
import com.syn.synold4s.R;
import com.syn.synold4s.adapter.AlertAdapter;
import com.syn.synold4s.bean.dto.MapAllDeviceDto;
import com.syn.synold4s.databinding.MonitoringDialogBinding;

public class GoogleMapMonitoringDialog extends BaseFragmentDialog<MonitoringDialogBinding> {

    private MapAllDeviceDto data;
    private AlertAdapter alertAdapter;

    public GoogleMapMonitoringDialog(Context context, MapAllDeviceDto data) {
        super(context);
        this.data = data;
    }

    @Override
    protected void initView() {
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        mBinding.ivClose.setOnClickListener(view -> dismiss());
        setData();
    }

    private void setData() {
        if (data == null) return;
        alertAdapter = new AlertAdapter(mContext);
        mBinding.rv.setLayoutManager(new LinearLayoutManager(mContext));
        mBinding.rv.setAdapter(alertAdapter);
        mBinding.rv.setItemAnimator(null);
        if (data.getAlertEvent() != null && data.getAlertEvent().size() > 0){
            mBinding.newDynamicLayout.setVisibility(View.VISIBLE);
            alertAdapter.submitList(data.getAlertEvent());
        }
        mBinding.tvName.setText(data.getDeviceName());
//        if (data.getPortalOWAt() != null) {
//            Date portalOWAt = data.getPortalOWAt();
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
//            String time = simpleDateFormat.format(portalOWAt);
//            mBinding.tvTime.setText(time);
//        }
        mBinding.tvTime.setText(data.getLastAt());
        String helmetImgUrl = SPUtil.getInstance().getString(SPName.API_URL, BASE_NET_URL) + HELMET_IMG_URL;
        ImageUtil.loadImg(mBinding.ivPhoto, helmetImgUrl+"400/" + data.getPhoto(), R.drawable.error_img);
    }

    @Override
    protected MonitoringDialogBinding getViewBinding() {
        return MonitoringDialogBinding.inflate(getLayoutInflater());
    }

    @Override
    protected String getShowTag() {
        return BOTTOM;
    }
}
